package com.google.zxing.client.android;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
//import android.widget.CompoundButton;
//import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.GridView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import android.widget.Toast;

public class MainActivity extends TabActivity implements OnCheckedChangeListener {
	private GridView gridView;
	// 图片的第一行文字
	private String[] titles = new String[] { "智能扫描", "手动输入", "历史记录", "使用说明", "软件更新" };
	// 图片的第二行文字
	private String[] description = new String[] { "扫描二维码标签查询", "输入标签信息查询", "标签扫描、查询历史记录","系统使用说明","客户端更新" };
	// 图片ID数组
	private int[] images = { R.drawable.icon_1_g, R.drawable.icon_2_g,R.drawable.icon_3_g, R.drawable.icon_4_g, R.drawable.icon_6_g };

	private RadioGroup mainTab;
	private Intent iSearch;
	private TabHost tabhost;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main);

		mainTab=(RadioGroup)findViewById(R.id.main_radio);
		mainTab.setOnCheckedChangeListener(this);
		tabhost=getTabHost();

		iSearch = new Intent(this, EncodeMainActivity.class);
		tabhost.addTab(tabhost.newTabSpec("iSearch")
				.setIndicator(getResources().getString(R.string.app_picker_name),
						getResources().getDrawable(R.drawable.icon_help))
						.setContent(iSearch));
		
		gridView = (GridView) findViewById(R.id.gridview);
		GridItemAdapter adapter = new GridItemAdapter(titles, images,
				description, this);
		gridView.setAdapter(adapter);
		// 选项点击事件
		gridView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View v,
					int position, long id) {
				Intent intent;
				switch (position + 1) {
				case 1:
					// 智能扫描
					intent = new Intent();
					intent.setClass(MainActivity.this, CaptureActivity.class);
					startActivity(intent);
					//Toast.makeText(MainActivity.this, "请将镜头对准条码，按要求操作";
					//		Toast.LENGTH_SHORT).show();
					break;
				case 2:
					// 手动输入
					intent = new Intent();
					intent.setClass(MainActivity.this, EncodeMainActivity.class);
					startActivity(intent);
					//Toast.makeText(MainActivity.this, "跳转手动输入",Toast.LENGTH_SHORT).show();
					break;
				case 3:
					// 历史记录
					intent = new Intent();
					intent.setClass(MainActivity.this,
							HistoryMainActivity.class);
					startActivity(intent);
					//Toast.makeText(MainActivity.this, "跳转历史记录",Toast.LENGTH_SHORT).show();
					break;
				case 4:
					// 使用说明
					intent = new Intent();
					intent.setClass(MainActivity.this, BookMainActivity.class);
					startActivity(intent);
					//Toast.makeText(MainActivity.this, "跳转使用说明",Toast.LENGTH_SHORT).show();
					break;
				case 5:
					// 软件更新
					intent = new Intent();
					intent.setClass(MainActivity.this, UpdateActivity.class);
					startActivity(intent);
					//Toast.makeText(MainActivity.this, "跳转软件更新",Toast.LENGTH_SHORT).show();
					break;
				}
			}
		});

		// 底部菜单栏事件//		((RadioButton) findViewById(R.id.radio_button0)).setOnCheckedChangeListener(this);
//		((RadioButton) findViewById(R.id.radio_button1)).setOnCheckedChangeListener(this);
		//((RadioButton) findViewById(R.id.radio_button2)).setOnCheckedChangeListener(this);
		//((RadioButton) findViewById(R.id.radio_scan)).setOnCheckedChangeListener(this);
		//((RadioButton) findViewById(R.id.radio_button0)).setOnCheckedChangeListener(this);
		
		
	}

	// 点击事件
	@Override
	//public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
	public void onCheckedChanged(RadioGroup group, int checkedID) {
		//if (isChecked) {
			Intent intent;
			//switch (buttonView.getId()) {
			switch (checkedID) {
			case R.id.radio_scan:
			    intent = new Intent();
				intent.setClass(MainActivity.this, CaptureActivity.class);
				startActivity(intent);
				//Toast.makeText(MainActivity.this, "请将镜头对准条码，按要求操作",Toast.LENGTH_SHORT).show();
				break;
			case R.id.radio_button0:
				this.tabhost.setCurrentTabByTag("iSearch");
				//intent = new Intent();
				//intent.setClass(MainActivity.this, EncodeMainActivity.class);
				//startActivity(intent);
				//Toast.makeText(MainActivity.this, "跳转手动输入", Toast.LENGTH_SHORT).show();
				break;
			case R.id.radio_button2:
				intent = new Intent();
				intent.setClass(MainActivity.this, HistoryMainActivity.class);
				startActivity(intent);
				//Toast.makeText(MainActivity.this, "跳转历史记录", Toast.LENGTH_SHORT).show();
				break;
			case R.id.radio_button3:
				intent = new Intent();
				intent.setClass(MainActivity.this, UpdateActivity.class);
				startActivity(intent);
				//Toast.makeText(MainActivity.this, "跳转使用说明", Toast.LENGTH_SHORT).show();
				break;
			//}
		}

	}
}